<template>
  <a-spin :spinning="confirmLoading" style="margin-top: 0px;margin-bottom: 0px">
    <j-form-container :disabled="formDisabled" >
      <!-- 主表单区域 -->
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-card title="当前状态" :bordered="false" >
          <a-row type="flex" justify="start">
            <a-col :span="12" >
              <tsl-step :list="steplist" :currentStatus="model.stepStatus"></tsl-step>
            </a-col>
          </a-row>
        </a-card>
        <a-divider />
        <a-row>
          <a-col :span="8" >
            <a-form-model-item label="单据编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">
              <a-input disabled v-model="model.code" placeholder="请输入单据编号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="入库类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="storageType">
              <j-dict-select-tag style="width: 200px" :disabled="isProcStorage" type="list" v-model="model.storageType"
                                 dictCode="rk_type" placeholder="请选择入库类型" :disabledVal="3"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="供货单位名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="supplierId">
              <a-input  v-model="model.supplierId" placeholder="请输入供货单位名称" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="批次号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lotNumber">
              <a-input  v-model="model.lotNumber" placeholder="请输入批次号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="进厂日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enteringDate">
              <a-input  v-model="model.enteringDate" placeholder="请输入进厂日期" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row v-show="!isProcStorage">
          <a-col :span="8" >
            <a-form-model-item label="宝洁供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bjSupplierCode">
              <a-input v-model="model.bjSupplierCode"  placeholder="宝洁供应商编码" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="宝洁采购订单号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bjProcurementCode">
              <a-input v-model="model.bjProcurementCode"  placeholder="宝洁采购订单号" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="8" >
            <a-form-model-item label="宝洁供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="bjSupplierName">
              <a-input v-model="model.bjSupplierName"  placeholder="宝洁供应商" ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
    <a-tabs
      :default-active-key="tabkeys[0]">
      <a-tab-pane tab="入库信息" :key="tabkeys[0]"  :forceRender="true">
        <a-card title="收货信息" :bordered='false'>
          <j-vxe-table
            keep-source
            :ref="refKeys[0]"
            :loading="bussPackageStorageMaterialTable.loading"
            :columns="bussPackageStorageMaterialTable.columns"
            :dataSource="bussPackageStorageMaterialTable.dataSource"
            :maxHeight="300"
            :disabled="formDisabled"
            :rowNumber="true"
            :rowSelection="true"
            :toolbar="true"
            :toolbarConfig="{slot: ['prefix', 'suffix'], btn: ['clearSelection']}"
            class="bold-border"
            @edit-closed="editMaterialClosedEvent"
            :clickSelectRow="true"
            rowSelectionType="radio"
          >
            <template    v-slot:toolbarSuffix>
              <a-button @click='addMaterialInfo' v-show="!bussinessDisable && !formDisabled">新增</a-button>
              <a-button @click='deleteMaterial' v-show="!formDisabled">删除</a-button>
<!--              <a-button @click='handleCK' v-show="!formDisabled">添加车辆信息</a-button>-->
              <a-button @click='clearCheck("materical")' v-show="!formDisabled">清空选择</a-button>
            </template>
            <template v-slot:erpLocationName="props">
              <tsl-warehouse v-model="props.value" :disabled="formDisabled" :rowData='props' @handlerOk="warehouseOk"></tsl-warehouse>
            </template>
            <template v-slot:supplierId="props">
              <tsl-mat-supplier v-model="props.value" :isDisabled="bussinessDisable && !formDisabled" :rowData='props'
                                @handlerOk="supplierOk"></tsl-mat-supplier>
            </template>
          </j-vxe-table>
        </a-card>
<!--        <a-card title="车辆信息" :bordered='false'>-->
<!--          <j-vxe-table-->
<!--            keep-source-->
<!--            :ref="refKeys[1]"-->
<!--            :loading="bussPackageStorageCarinfoTable.loading"-->
<!--            :columns="bussPackageStorageCarinfoTable.columns"-->
<!--            :dataSource="bussPackageStorageCarinfoTable.dataSource"-->
<!--            :maxHeight="300"-->
<!--            :disabled="formDisabled"-->
<!--            :rowNumber="true"-->
<!--            :rowSelection="true"-->
<!--            :toolbar="true"-->
<!--            :autoResize="true"-->
<!--            :toolbarConfig="{slot: ['prefix', 'suffix'], btn: ['clearSelection']}"-->
<!--            @edit-closed="editClosedEvent"-->
<!--            :clickSelectRow="true"-->

<!--          >-->
<!--            <template    v-slot:toolbarSuffix>-->
<!--              <a-button @click='deleteCarinfo' v-show="!formDisabled">删除</a-button>-->
<!--              <a-button @click='clearCheck("car")' v-show="!formDisabled">清空选择</a-button>-->
<!--            </template>-->
<!--          </j-vxe-table>-->
<!--        </a-card>-->
      </a-tab-pane>
      <a-tab-pane tab="状态履历修改" :key="tabkeys[1]"  :forceRender="true">
        <a-card :bordered='false'>
          <tsl-history  dataTable="package_storage"  :dataId="model.id"></tsl-history>
        </a-card>
      </a-tab-pane>
    </a-tabs>

    <erp-supplier-list ref='supplier' @handlerOk='supplierOk'> </erp-supplier-list>
    <erp-good-list ref='good'
                   :category="2"
                   @handlerOk='goodOk'
                   checkval='checkbox'
                   :supplierId="model.supplierId"></erp-good-list>

  </a-spin>
</template>
<script>
import { getAction, postAction } from '@/api/manage'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import { getRefPromise,VALIDATE_FAILED} from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from '@/components/jeecg/JFormContainer'
import BussMaterialProcurementList  from '@/views/modules/procurement/BussMaterialProcurementList'
import ErpSupplierList from '@/views/modules/supplier/ErpSupplierList'
import ErpGoodList from '@/views/modules/goods/ErpGoodsListModal'
import ErpLocationList from '@/views/modules/location/ErpLocationList'
import DetailsModal from '@/components/modal/DetailsModal'
import TslStep from '@/components/tsl/TslStep'
import moment from 'dayjs'
import TslWarehouse from '@comp/tsl/TslWarehouse.vue'
import TslMatSupplier from '@comp/tsl/cell/TslMatSupplier.vue'
import TslHistory from '@comp/tsl/TslHistory.vue'
import TslSupplier from '@comp/tsl/TslSupplier.vue'

export default {
  name: 'BussStorageNoticeForm',
  mixins: [JVxeTableModelMixin],
  components: {
    JFormContainer,BussMaterialProcurementList,ErpSupplierList,ErpGoodList,ErpLocationList,
    DetailsModal,TslStep,TslWarehouse,TslMatSupplier,TslHistory,TslSupplier
  },
  data() {
    const actualNum = (rule, value, callback) => {
      callback(new Error('请再次输入密码'));
    };
    return {
      // bussinessDisable: false,
      procSelectRows: [],
      toolBtn: [ 'remove', 'clearSelection'],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      model:{
        stepStatus: 0,
        storageType: null
      },
      steplist:[
        {title:'草稿'},{title:'采购确认'},{title:'入库'}
      ],
      rules: {
        // num: [
        //   {required: true, message: '必须输入序号'},
        // ],
      },
      noticeMaterialRowNum: 0,
      carRowNum: 0,
      // 新增时子表默认添加几行空数据
      addDefaultRowNum: 0,
      validatorRules: {
        erpLocationId: [{required: true, message: '请选择库位'}],
      },
      //resetScrollTop
      historyOption: [],
      refKeys: ['bussStorageNoticeMaterial', ],
      tableKeys:['bussStorageNoticeMaterial', ],
      tabkeys: ['material','uphistorys'],
      activeKey: 'material',
      // 入库通知单原料单
      bussPackageStorageMaterialTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: '行项目',
            key: 'rowNum',
            type: JVXETypes.normal,
            width:"70px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '排产单号',
            key: 'schedulingCode',
            type: JVXETypes.input,
            width: '100px',
          },
          {
            title: '包材编号',
            key: 'materialCode',
            type: JVXETypes.normal,
            width: '120px',
          },
          {
            title: '包材名称',
            key: 'materialName',
            type: JVXETypes.normal,
            width: '120px',
          },
          {
            title: '供应商要求名称',
            key: 'materialSupplierName',
            type: JVXETypes.input,
            width: '120px',
          },
          {
            title: '规格',
            key: 'spec',
            type: JVXETypes.normal,
            width: '70px',
          },
          {
            title: '单位',
            key: 'meUnit',
            type: JVXETypes.normal,
            width: '70px',
            dictCode: 'ji_unit',
          },
          {
            title: '库位',
            key: 'erpLocationId',
            type: JVXETypes.slot,
            slotName: 'erpLocationName',
            width: '200px',
            validateRules: [{ required: true, message: '请选择${title}'}]
          },
          {
            title: '采购订单数量',
            key: 'procurementNum',
            type: JVXETypes.normal,
            width: '70px',
          },
          {
            title: '已到数量',
            key: 'arrivalNum',
            type: JVXETypes.normal,
            width: '70px',
          },
          {
            title: '未到数量',
            key: 'notArrivalNum',
            type: JVXETypes.normal,
            width: '70px',
            formatter({cellValue, row, column}) {
              return 123;
            }
          },
          {
            title: '数量',
            key: 'num',
            type: JVXETypes.inputNumber,
            width: '70px',
          },
          {
            title: '备注',
            key: 'remark',
            type: JVXETypes.input,
            width: '120px',
          },
          {
            title: '包材采购订单编号',
            key: 'procurementCode',
            type: JVXETypes.normal,
            width: '100px',
          },
          {
            title: '生产日期',
            key: 'manufactureDate',
            type: JVXETypes.date,
            width: '70px',
          },
          {
            title: '限用日期',
            key: 'expiryDate',
            type: JVXETypes.date,
            width: '70px',
          },
          {
            title: '质检状态',
            key: 'qcStatus',
            type: JVXETypes.normal,
            width: '70px',
          },
        ]
      },
      // 入库通知单-车辆信息
      bussPackageStorageCarinfoTable: {
        loading: false,
        dataSource: [],
        columns: [
          {
            title: 'id',
            key: 'id',
            type: JVXETypes.hidden,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '行项目',
            key: 'rowNum',
            type: JVXETypes.normal,
            width:"70px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '通知单id',
            key: 'noticeId',
            type: JVXETypes.hidden,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '车牌号',
            key: 'carNum',
            type: JVXETypes.input,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '物料编号',
            key: 'materialCode',
            type: JVXETypes.normal,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '物料名称',
            key: 'materialName',
            type: JVXETypes.normal,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '单位',
            key: 'meUnit',
            type: JVXETypes.select,
            width: '150px',
            dictCode: 'ji_unit',
            disabled: true
          },
          {
            title: '原发数',
            key: 'originalNum',
            type: JVXETypes.inputNumber,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '实际数量',
            key: 'actualNum',
            type: JVXETypes.inputNumber,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          {
            title: '备注',
            key: 'remark',
            type: JVXETypes.input,
            width:"150px",
            placeholder: '请输入${title}',
            defaultValue:'',
          },
          // {
          //   title: '操作',
          //   key: 'action',
          //   type: JVXETypes.slot,
          //   fixed: 'right',
          //   minWidth: '200px',
          //   align: 'center',
          //   slotName: 'action',
          // }
        ]
      },
      NoticeMaterialTable: '',
      CarTableRef: '',
      isProcStorage: false,
      url: {
        add: "/business/packageStorage/add",
        edit: "/business/packageStorage/edit",
        queryById: "/business/packageStorage/queryById",
        bussStorageNoticeCarinfo: {
          list: '/business/bussStorageNotice/queryBussStorageNoticeCarinfoByMainId'
        },
        bussPackageStorageMaterial: {
          list: '/business/packageStorage/queryPackageStorageMaterialByMainId'
        },
      }
    }
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    },
    /*流程自定义表单数据*/
    customFormData:{
      type:Object,
      default:()=>{return {}},
      required:false
    },
  },
  computed: {
    formDisabled(){
      return this.disabled
    },
    bussinessDisable(){
      if(this.model.storageType  && this.model.storageType == 3){
        return true;
      }
      return false;
    }
  },
  created () {

  },
  mounted() {
    this.$nextTick(() => {
      this.getAllTable().then(tables=>{
        this.NoticeMaterialTable = tables[0]
        // this.CarTableRef = tables[1]
      })
      setTimeout(() => {
        if( !this.model.id ){
          let rows = this.NoticeMaterialTable.getNewDataWithId()
          if(rows.length > 0){
            this.NoticeMaterialTable.removeRowsById(rows[0].id)
          }
          this.NoticeMaterialTable.syncHeaderScroll = true;
        }
        this.scrollTop()
      },500)
    })
  },
  methods: {
    warehouseOk({result,row}){
      this.bussPackageStorageMaterialTable.dataSource.forEach(item=>{
        if(item.materialId == row.materialId && item.rowNum == row.rowNum){
          item.erpLocationId = result.id
          item.erpLocationName = result.name
          item.erpLocationCode = result.code
          item.erpWarehouseName = result.warehouseName
          item.erpWarehouseCode = result.warehouseCode
        }
      })
      this.scrollTop()
    },
    editMaterialClosedEvent({ row, column }){
      let xTable = this.$refs.bussStorageNoticeMaterial
      let field = column.property
      let cellValue = row[field]
      let _this = this
      // 判断单元格值是否被修改
      this.$nextTick(() => {
        // if('batchNum' === field){
        //   // if (xTable.isUpdateByRow(row, field)) {  // 判断值是否修改，但是不准确，有时会判断错误
        //   this.bussPackageStorageMaterialTable.dataSource.forEach(mater => {
        //     mater.batchNum = cellValue
        //   })
        //   // }
        // }else if('createDate' === field || 'expiryDate' === field ){
        //   // if (xTable.isUpdateByRow(row, field)) {
        //   console.log(row)
        //   if(typeof row.createDate !== "undefined" && typeof row.expiryDate !== "undefined"){
        //     const date1 = moment(row.createDate);
        //     const date2 = moment(row.expiryDate);
        //     console.log(date2.diff(date1,'days'))
        //     if(date2.diff(date1,'days')<30){
        //       _this.$message.warn('限用日期是否输入正确!')
        //     }
        //   }
        //   // }
        // }
      })
    },
    editClosedEvent ({ row, column }){
      // 车辆数量修改，物料数量跟着变动
      let xTable = this.$refs.bussStorageNoticeCarinfo
      let field = column.property
      let cellValue = row[field]
      // 判断单元格值是否被修改
      this.$nextTick(() => {
        // if('actualNum' === field || 'originalNum' === field){
        //   // if (xTable.isUpdateByRow(row, field)) {
        //   let { rowNum, materialId, originalNum, actualNum } = row
        //   this.bussPackageStorageMaterialTable.dataSource.forEach(mater => {
        //     if('originalNum' === field){
        //       if(mater.materialId === materialId && mater.rowNum === rowNum){
        //         mater.originalNum = originalNum
        //         return;
        //       }
        //     }
        //
        //     if(mater.materialId === materialId && mater.rowNum === rowNum){
        //       let actualNum = 0
        //       let originalNum = 0
        //       this.bussPackageStorageCarinfoTable.dataSource.forEach(car =>{
        //         if(car.rowNum === mater.rowNum && mater.materialId === car.materialId ){
        //           actualNum +=  car.actualNum
        //           originalNum += car.originalNum
        //         }
        //       })
        //       if(this.model.storageType === 3){
        //         let targetObj = Object.assign({},mater);
        //         targetObj.originalNum = originalNum
        //         targetObj.actualNum = actualNum
        //         if(targetObj.id.indexOf('row')>=0){
        //           targetObj.id = ''
        //         }
        //         postAction('/business/bussStorageNotice/checkProcMaterialNum',targetObj).then(res =>{
        //           console.log('检查的数据',res);
        //           const {code,message} = res
        //           if(code == 200){
        //             mater.originalNum = originalNum
        //             mater.actualNum = actualNum
        //             this.NoticeMaterialTable.resetScrollTop();
        //           }else{
        //             this.$message.warn(message)
        //           }
        //         })
        //       }else{
        //         mater.originalNum = originalNum
        //         mater.actualNum = actualNum
        //       }
        //     }
        //   });
        //   this.NoticeMaterialTable.resetScrollTop();
        // }
      })
    },
    edit(record) {
      if (typeof this.editBefore === 'function') this.editBefore(record)
      this.visible = true
      this.activeKey = this.refKeys[0]
      this.$refs.form.resetFields()
      this.model = Object.assign({}, record)
      if (typeof this.editAfter === 'function') this.editAfter(this.model)
    },
    addProc(){
      if(this.procSelectRows.length > 0){
        const rows = this.procSelectRows
        this.model.storageType = 3
        this.isProcStorage = true
        rows.forEach((item,index)=>{
          let detail = {}
          detail.rowNum = this.getRowNum()
          detail.procurementCode = item.code
          detail.procurementDetailId = item.id
          detail.warehouseDate = moment(new Date()).format('YYYY-MM-DD')
          detail.materialId = item.materialId
          detail.materialName = item.materialName
          detail.materialCode = item.materialCode
          detail.supplierId = item.supplierId
          detail.supplierCode = item.supplierCode
          detail.meUnit = item.meUnit_dictText
          detail.spec = item.spec
          detail.procurementNum = item.procurementNum
          detail.arrivalNum = item.arrivalNum
          detail.notArrivalNum = detail.procurementNum - detail.arrivalNum
          this.bussPackageStorageMaterialTable.dataSource.push(detail)
        })
      }
    },
    addMaterialInfo(){
      if(!this.model.storageType){
        this.$message.warn('请选择入库类型！')
        return;
      }
      if(this.model.storageType == 3){
        //采购
        // this.onSearchProcurement()
      }else{
        this.onSearchMaterial();
      }
    },
    deleteCarinfo(props){
      // 删除物料
      let rows =  this.CarTableRef.selectedRows;
      if(rows.length<=0){
        this.$message.warn('请选择车辆信息！')
        return;
      }
      rows.forEach(row => {
        this.bussPackageStorageCarinfoTable.dataSource = this.bussPackageStorageCarinfoTable.dataSource.filter(item=>item.id !== row.id)
      })
    },
    handleCK(){
      // 添加车辆信息
      let rows =  this.NoticeMaterialTable.selectedRows;
      if(rows.length === 0 || rows.length > 1){
        this.$message.warn('请选择一个收货信息！')
        return;
      }
      rows.forEach(item=>{
        let detail = {
          actualNum: '',
          originalNum: '',
          rowNum: item.rowNum,
          materialId: item.materialId,
          materialCode: item.materialCode,
          materialName: item.materialName,
          meUnit: item.meUnit
        }
        this.bussPackageStorageCarinfoTable.dataSource.push(detail)
      })
    },
    getPfCode() {
      if(this.model.id){
        return;
      }
      postAction('/sys/fillRule/executeRuleByCode/rktzd', {}).then(res => {
        this.model.code = res.result;
      })
    },
    deleteCarByMat(code,rowNum){
      // 删除车辆信息
      let data = this.bussPackageStorageCarinfoTable.dataSource.filter(item=> item.materialCode !== code && item.rowNum !== rowNum)
      this.bussPackageStorageCarinfoTable.dataSource =  data
    },
    goodOk(rows){
      let _this = this;
      rows.forEach((item,index)=>{
        let obj = {}
        obj.materialId= item.id
        obj.materialName= item.name
        obj.materialCode= item.code
        obj.spec= item.noneSpec
        obj.meUnit= item.meUnit
        obj.rowNum = this.getRowNum()
        obj.warehouseDate = moment(new Date()).format('YYYY-MM-DD')
        this.bussPackageStorageMaterialTable.dataSource.push(obj)
      })
      this.scrollTop()
    },
    deleteMaterial(){
      // 删除物料
      let rows =  this.NoticeMaterialTable.selectedRows;
      if(rows.length<=0){
        this.$message.warn('请选择收货信息！')
        return;
      }
      rows.forEach(row=>{
        this.bussPackageStorageMaterialTable.dataSource = this.bussPackageStorageMaterialTable.dataSource.filter(item=>item.id !== row.id)
        this.deleteCarByMat(row.materialCode,row.rowNum);
      })
    },
    clearCheck(obj){
      // if(obj == 'car'){
      //   this.CarTableRef.clearSelection();
      // }else{
        this.NoticeMaterialTable.clearSelection();
      // }
    },
    onSearchMaterial(){
      this.$nextTick(() => {
        this.$refs.good.add()
      })
    },
    supplierOk({row,value}){
      this.bussPackageStorageMaterialTable.dataSource.forEach(item=>{
        if(item.materialId == row.materialId && item.rowNum == row.rowNum){
          item.supplierId = value
        }
      })
      this.scrollTop()
    },
    onSearchProcurement(){
      // 采购订单
      this.$nextTick(() => {
        // this.$refs.procurement.add();
      })
    },
    addBefore(){
      this.bussPackageStorageCarinfoTable.dataSource = []
      this.bussPackageStorageMaterialTable.dataSource = []
    },
    getAllTable() {
      let values = this.tableKeys.map(key => getRefPromise(this, key))
      return Promise.all(values)
    },
    /** 调用完edit()方法之后会自动调用此方法 */
    editAfter() {
      // 加载子表数据
      if (this.model.id) {
        let params = { id: this.model.id }
        // this.requestSubTableData(this.url.bussStorageNoticeCarinfo.list, params, this.bussStorageNoticeCarinfoTable)
        this.requestSubTableData(this.url.bussPackageStorageMaterial.list, params, this.bussPackageStorageMaterialTable)
      }else {
        this.getPfCode();
      }
    },
    //校验所有一对一子表表单
    validateSubForm(allValues){
      if(allValues.tablesValue[0].tableData.length == 0){
        this.$message.error('请添加收货信息！')
        return false;
      }
      return new Promise((resolve,reject)=>{
        Promise.all([
        ]).then(() => {
          resolve(allValues)
        }).catch(e => {
          if (e.error === VALIDATE_FAILED) {
            // 如果有未通过表单验证的子表，就自动跳转到它所在的tab
            this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
          } else {
            console.error(e)
          }
        })
      })
    },
    /** 整理成formData */
    classifyIntoFormData(allValues) {
      let _this = this;
      let main = Object.assign(this.model, allValues.formValue)
      return {
        ...main, // 展开
        packageStorageMaterialList: _this.processingData( allValues.tablesValue[0].tableData),
        // bussStorageNoticeCarinfoList: _this.processingData(allValues.tablesValue[1].tableData),
      }
    },
    processingData(data){
      let newJsonArray = data.map(item => {
        return { ...item, id: item.id && item.id.indexOf('row')>=0?'':item.id  };
      });
      return newJsonArray;
    },
    validateError(msg){
      this.$message.error(msg)
    },
    updateNoticeMaterial(rowNum,field,fieldval){
      this.bussPackageStorageMaterialTable.dataSource.forEach(item => {
        if(item.rowNum == rowNum){
          item[field] = fieldval
        }
      })
    },
    scrollTop(){
      // 数据变动会出现滚动条无法滚动的情况，调用这个
      this.NoticeMaterialTable.resetScrollTop();
      // this.CarTableRef.resetScrollTop();
      // getRefPromise(this, 'bussStorageNoticeMaterial').then(vxeTable => {
      //   vxeTable.resetScrollTop()
      // })
    },
    getRowNum(){
      let source = this.bussPackageStorageMaterialTable.dataSource
      if(source.length === 0){
        return '0001'
      }
      let { rowNum } = source[source.length-1]
      let nextRowNum = Number(rowNum) + 1;
      if(nextRowNum < 10){
        return '000'+ nextRowNum;
      }else if(nextRowNum < 100){
        return '00'+ nextRowNum;
      }else if(nextRowNum < 1000){
        return '0'+ nextRowNum;
      }else {
        return String(nextRowNum)
      }
    }
  }
}
</script>
<style scoped>
</style>
<style>

/*.bold-border .vxe-table--main-wrapper .vxe-table .vxe-body--row .vxe-body--column {*/
/*  border: 2px solid #ccc; !* 设置边框粗细和颜色 *!*/
/*}*/

/*.bold-border .vxe-table--main-wrapper .vxe-table .vxe-footer--column {*/
/*  border-top: 2px solid #ccc; !* 表尾也可以加粗 *!*/
/*}*/

/*.bold-border table, tr, td {*/
/*  border: 1px solid black; !* 黑色边框，1px宽度 *!*/
/*}*/
/*.bold-border table, th, td {*/
/*  border: 1px solid black; !* 黑色边框，1px宽度 *!*/
/*}*/
</style>